import Mock from 'mockjs'
const Random = Mock.Random

// 生成科目稳定性数据
const generateSubjectStability = (name, isUnstable = false) => {
  const stabilityScore = isUnstable ? Random.float(4, 7, 1, 1) : Random.float(7, 10, 1, 1)
  const standardDeviation = isUnstable ? Random.float(6, 12, 1, 1) : Random.float(2, 6, 1, 1)
  const variationCoefficient = isUnstable ? Random.float(0.08, 0.15, 2, 2) : Random.float(0.02, 0.08, 2, 2)
  const riskLevel = isUnstable ? 'high' : Random.pick(['low', 'medium'])
  
  // 生成成绩趋势数据
  const baseScore = Random.integer(70, 95)
  const trend = []
  for (let i = 0; i < 7; i++) {
    const variation = isUnstable ? Random.integer(-15, 15) : Random.integer(-8, 8)
    trend.push(Math.max(0, Math.min(100, baseScore + variation)))
  }
  
  return {
    name,
    stabilityScore,
    standardDeviation,
    variationCoefficient,
    isUnstable,
    riskLevel,
    trend
  }
}

// 生成稳定性分析数据
const generateStabilityData = () => {
  const subjects = [
    generateSubjectStability('数学', true), // 数学不稳定
    generateSubjectStability('英语', false),
    generateSubjectStability('语文', false),
    generateSubjectStability('物理', false),
    generateSubjectStability('化学', false),
    generateSubjectStability('生物', false)
  ]
  
  const unstableSubjects = subjects.filter(subject => subject.isUnstable).map(subject => subject.name)
  
  const recommendations = [
    '数学科目成绩波动较大，需要加强基础知识的巩固',
    '建议分析数学成绩波动的原因，制定针对性的学习策略',
    '可以寻求老师的帮助，了解数学学习中的薄弱环节',
    '建议制定详细的学习计划，合理安排各科目学习时间',
    '定期进行自我评估，及时调整学习方法'
  ]
  
  return {
    subjects,
    unstableSubjects,
    recommendations: Random.shuffle(recommendations).slice(0, 3)
  }
}

// 获取成绩稳定性分析数据
Mock.mock(/\/api\/student\/stability/, 'get', () => {
  return {
    code: 200,
    message: '操作成功',
    data: generateStabilityData()
  }
}) 